package com.excel.generation;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Excel读取监听器
 *
 * @author 一杯香飘飘
 * @date 2025/2/6 9:59
 **/
@Data
@Slf4j
@EqualsAndHashCode(callSuper = true)
public class ExcelListener extends AnalysisEventListener<ReadExcelEntity> {

    /**
     * 数据存储容器
     */
    private List<Map<String, String>> data;

    public ExcelListener(List<Map<String, String>> data) {
        this.data = data;
    }


    @Override
    public void invoke(ReadExcelEntity readExcelEntity, AnalysisContext context) {
        Map<String, String> dataMap  = new HashMap<>();
        dataMap.put(readExcelEntity.getFirstLine(), readExcelEntity.getSecondLine());
        data.add(dataMap);
    }


    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        log.info("所有数据解析完成！");
    }
}
